﻿Imports System.Xml
Imports System.Data.OleDb

Public Class Rss
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.ContentType = "application/rss+xml"
        Response.ContentEncoding = Encoding.UTF8
        Dim rssWriter As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        openRss(rssWriter)
        Dim researchT As DataTable = GetDateSet()
        otherRss(rssWriter, researchT)
        endRss(rssWriter)
        rssWriter.Flush()
        Response.End()

    End Sub
    Private Sub openRss(ByVal rssWriter As XmlTextWriter)
        rssWriter.WriteStartElement("rss")
        rssWriter.WriteAttributeString("version", "2.0")
        rssWriter.WriteStartElement("channel")
        rssWriter.WriteElementString("title", "Research Explorer- Mobile Ad Hoc Networks")
        rssWriter.WriteElementString("link", "ResearchList.aspx")
        rssWriter.WriteElementString("description", "It is about recommended MANET Researches")
    End Sub
    Private Sub otherRss(ByVal rssWriter As XmlTextWriter, ByVal info As DataTable)
        For Each accessCol As DataRow In info.Rows
            rssWriter.WriteStartElement("item")
            rssWriter.WriteElementString("title", accessCol(1).ToString)
            rssWriter.WriteElementString("link", "ResearchListDetails.aspx?ID=" & accessCol(0).ToString)
            rssWriter.WriteElementString("description", "The research is: " & accessCol(7).ToString)
            rssWriter.WriteEndElement()
        Next
    End Sub
    Private Sub endRss(ByVal rssWriter As XmlTextWriter)
        rssWriter.WriteEndElement()
        rssWriter.WriteEndElement()

    End Sub
    Private Function GetDateSet() As DataTable
        Dim researchT = New DataTable()
        Dim conn = New OleDbConnection(ConfigurationManager.ConnectionStrings("FinalConnectionString").ConnectionString)
        Dim sql = New String("SELECT * FROM [Researches]")
        Dim connSql = New OleDbDataAdapter(sql, conn)
        connSql.Fill(researchT)
        Return researchT
    End Function
End Class